<%@page import="com.entity.ProType"%>
<%@page import="com.biz.ProTypeBizImpl"%>
<%@page import="com.entity.UserInfo"%>
<%@page import="com.biz.ProductBizImpl"%>
<%@page import="com.entity.Product"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>修改商品</title>
    
	<meta charset="UTF-8">
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="css/add-mod-style.css">
	<script src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript">
		function checkPname(){
			var pname=$("#pname").val();
			$("#pname+span").html("");
			if(pname==''){
				$("#pname+span").html("名称不能为空");
				return false;
			}
			return true;
		}
		
		function checkPrice(){
			var price=$("#price").val();
			$("#price+span").html("");
			if(price==''){
				$("#price+span").html("价格不能为空");
				return false;
			}else if(isNaN(price) || parseFloat(price)<0){
				$("#price+span").html("价格不符合规范");
				return false;
			}
			return true;
		}
		$(function(){
			$("#pname").blur(function(){
				checkPname();
			});
			$("#price").blur(function(){
				checkPrice();
			});
			$("#addform").submit(function(){
				if(checkPname() && checkPrice()){
					return true;
				}
				return false;
			});
		});
	</script>
  </head>
  <body>
    <form action="admin/product/domod" method="post" id="addform">
      <table>
      	<tr>
        	<td colspan="2">
        		<h2>修改商品</h2>
        	</td>
        </tr>
        <tr>
        	<td colspan="2">
        		<input type="hidden" name="id" id="id" value="${pro.id }"/>
        	</td>
        </tr>
        <tr>
          	<td>名称：</td>
          	<td><input type="text" name="pname" id="pname" value="${pro.pname }"/><span></span></td>
        </tr>
        <tr>
          	<td>价格：</td>
         	<td><input type="text" name="price" id="price" value="${pro.price }"/><span></span></td>
        </tr>
        <tr>
         	<td>库存：</td>
          	<td><input type="number" name="stock" id="stock" value="${pro.stock }"/></td>
        </tr>
        <tr>
          	<td>类别：</td>
          	<td><select name="kind" id="kind">
          		<% 
          			List<ProType> ptlist=new ProTypeBizImpl().showProType();
          			pageContext.setAttribute("ptlist", ptlist);
          		%>
          		<c:forEach items="${ptlist }" var="pt">
          			<option value="${pt.id }" ${pt.id==pro.kind? "selected":""}>${pt.tname }</option>
          		</c:forEach>
          		</select><span></span>
          	</td>
        </tr>
        <tr>
          	<td>说明：</td>
          	<td>
          		<textarea name="comments" id="comments">${pro.comments }</textarea>
        	</td>
        </tr>
        <tr>
        	<td colspan="2">
        		<input type="submit" value="修&nbsp;&nbsp;&nbsp;&nbsp;改"/>
        	</td>
        </tr>
      </table>
    </form>
  </body>
</html>
